package com.bawei.module_home.ui.sign.viewmodel

import androidx.lifecycle.MutableLiveData
import com.bawei.lib_common.base.BaseViewModel
import com.bawei.lib_common.base.state.Failed
import com.bawei.lib_common.base.state.Loading
import com.bawei.lib_common.base.state.RequestEvent
import com.bawei.lib_common.base.state.Success
import com.bawei.module_home.model.SignParam
import com.bawei.module_home.model.SignResult
import com.bawei.module_home.ui.sign.repository.SignRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import javax.inject.Inject

/**
 *author：yjk
 *description:
 *date：2025/6/12
*/
@HiltViewModel
class SignViewModel @Inject constructor(private val repository: SignRepository):BaseViewModel() {
    val signResult = MutableLiveData<SignResult>()
    private val _mSign= MutableStateFlow<RequestEvent>(Loading)
    val signState
        get() =_mSign.asStateFlow()
    fun signIn(signParam: SignParam){
        execute(
            action = repository.postSign(signParam),
            onStart = {
                _mSign.value = Loading
            },
            onError = {
                _mSign.value = Failed(it)
            },
            onFinish = {
                signResult.value = it.data
                _mSign.value = Success
            }
        )
    }
}